from uscarp import *

db = sMysql('nba','team1','12345qwert','139.198.14.181')
sql = 'select id from player_base'
db.execute(sql)
base_players = {p[0] for p in db.content() if p[0] >100}
with open('records.json', 'r') as json_file:
    records = json.load(json_file)
team=list()
players = set()
for yrecords in records:
    tmp = dict()
    for p in yrecords:
        t=yrecords[p][0]
        players.add(int(p))
        if t not in tmp:
            tmp[t]={p}
        else:
            tmp[t].add(p)
    team.append(tmp)

res = dict()
for rc in team:
    for t in rc:
        tmp = set()
        for p1 in rc[t]:
            for p2 in rc[t]:
                if int(p1) not in base_players and int(p1) not in base_players:
                    continue
                if (p1,p2) in tmp or (p2,p1) in tmp:
                    continue
                else:
                    if (int(p1),int(p2)) not in res:
                        res[(int(p1), int(p2))] =1
                    else:
                        res[(int(p1),int(p2))]+=1
                    tmp.add((p1,p2))

res = [(k[0],k[1],v) for k,v in res.items()]
print(res)
with open('teammate.json', 'w') as json_file:
    json.dump(res, json_file)